package test.wechat.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lodsve.wechat.api.customer.WeChatCustomerService;
import lodsve.wechat.api.customer.WeChatCustomerTidingsService;
import lodsve.wechat.beans.CustomerServer;
import lodsve.wechat.beans.tidings.TextTidings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * .
 *
 * @author sunhao(sunhao.java@gmail.com)
 * @version V1.0, 16/3/4 下午2:16
 */
@Api(value = "客服人员操作接口", description = "客服人员操作接口")
@RestController
@RequestMapping("/weixin/customer")
public class CustomerController {
    @Autowired
    private WeChatCustomerService customerService;
    @Autowired
    private WeChatCustomerTidingsService customerTidingsService;

    @ApiOperation(value = "增加客服", notes = "增加客服")
    @ApiResponses({@ApiResponse(code = 200, message = "增加客服成功")})
    @RequestMapping(value = "/add", method = RequestMethod.POST, produces = "application/json")
    public void add(@ApiParam(name = "account", value = "账号") @RequestParam("account") String account,
                    @ApiParam(name = "nickName", value = "昵称") @RequestParam("nickName") String nickName,
                    @ApiParam(name = "password", value = "登录密码") @RequestParam("password") String password) {
        customerService.add(account, nickName, password);
    }

    @ApiOperation(value = "修改客服", notes = "修改客服")
    @ApiResponses({@ApiResponse(code = 200, message = "修改客服成功")})
    @RequestMapping(value = "/update", method = RequestMethod.POST, produces = "application/json")
    public void update(@ApiParam(name = "account", value = "账号") @RequestParam("account") String account,
                       @ApiParam(name = "nickName", value = "昵称") @RequestParam("nickName") String nickName,
                       @ApiParam(name = "password", value = "登录密码") @RequestParam("password") String password) {
        customerService.update(account, nickName, password);
    }

    @ApiOperation(value = "删除客服", notes = "删除客服")
    @ApiResponses({@ApiResponse(code = 200, message = "删除客服成功")})
    @RequestMapping(value = "/delete", method = RequestMethod.DELETE, produces = "application/json")
    public void delete(@ApiParam(name = "account", value = "账号") @RequestParam("account") String account,
                       @ApiParam(name = "nickName", value = "昵称") @RequestParam("nickName") String nickName,
                       @ApiParam(name = "password", value = "登录密码") @RequestParam("password") String password) {
        customerService.delete(account, nickName, password);
    }

    @ApiOperation(value = "获取所有客服", notes = "获取所有客服")
    @ApiResponses({@ApiResponse(code = 200, message = "获取所有客服成功")})
    @RequestMapping(value = "/list", method = RequestMethod.GET, produces = "application/json")
    @ResponseBody
    public List<CustomerServer> list() {
        return customerService.list();
    }

    @ApiOperation(value = "客服发送消息", notes = "客服发送消息")
    @ApiResponses({@ApiResponse(code = 200, message = "客服发送消息成功")})
    @RequestMapping(value = "/send", method = RequestMethod.POST, produces = "application/json")
    public void send(@ApiParam(name = "textTidings", value = "文本消息") @RequestBody TextTidings textTidings) {
        customerTidingsService.send(textTidings);
    }
}
